#include "SoundPlayer.h"
#include "../SGD Wrappers/SGD_AudioManager.h"
#include "../SGD Wrappers/SGD_Event.h"


SoundPlayer::SoundPlayer() : Listener(this)
{
	Listener::RegisterForEvent("PLAYERHURT");
	Listener::RegisterForEvent("GRAPPLEFIRE");
	Listener::RegisterForEvent("GRAPPLECONNECT");
	Listener::RegisterForEvent("ENEMYCOLLIDE");
	Listener::RegisterForEvent("PLANETCOLLIDE");
	Listener::RegisterForEvent("LIGHTORBCOLLIDE");
	Listener::RegisterForEvent("ENEMYFIRE");
	Listener::RegisterForEvent("ACHEIVEMENT");
	Listener::RegisterForEvent("GRAPPLEDETACH");
	Listener::RegisterForEvent("MENUMOVE");
	Listener::RegisterForEvent("MENUSELECT");
}

SoundPlayer::~SoundPlayer()
{

}

void SoundPlayer::HandleEvent(const SGD::Event* event)
{
	if (event->GetEventID() == "PLAYERHURT")
		audio->PlayAudio(playerHurt);
	else if (event->GetEventID() == "GRAPPLEFIRE")
		audio->PlayAudio(grappleFire);
	else if (event->GetEventID() == "GRAPPLECONNECT")
		audio->PlayAudio(grappleConnect);
	else if (event->GetEventID() == "ENEMYCOLLIDE")
		audio->PlayAudio(enemyCollide);
	else if (event->GetEventID() == "PLANETCOLLIDE")
		audio->PlayAudio(planetCollide);
	else if (event->GetEventID() == "LIGHTORBCOLLIDE")
		audio->PlayAudio(lightOrbCollide);
	else if (event->GetEventID() == "ENEMYFIRE")
		audio->PlayAudio(enemyFire);
	else if (event->GetEventID() == "ACHEIVEMENT")
		audio->PlayAudio(acheivement);
	else if (event->GetEventID() == "GRAPPLEDETACH")
		audio->PlayAudio(grappleDetach); 
	else if (event->GetEventID() == "MENUMOVE")
		audio->PlayAudio(menuMove); 
	else if (event->GetEventID() == "MENUSELECT")
		audio->PlayAudio(menuSelect);

}

void SoundPlayer::Enter()
{
	audio = SGD::AudioManager::GetInstance();
	playerHurt = audio->LoadAudio("resources/audio/playerhurt.wav");
	grappleFire = audio->LoadAudio("resources/audio/grapplefire.wav");
	grappleConnect = audio->LoadAudio("resources/audio/grappleconnect.wav");
	enemyCollide = audio->LoadAudio("resources/audio/enemycollide.wav");
	planetCollide = audio->LoadAudio("resources/audio/planetcollide.wav");
	lightOrbCollide = audio->LoadAudio("resources/audio/lightorbcollide.wav");
	enemyFire = audio->LoadAudio("resources/audio/enemyfire.wav");
	acheivement = audio->LoadAudio("resources/audio/achievemnt.wav");
	grappleDetach = audio->LoadAudio("resources/audio/grappledetach.wav");
	menuMove = audio->LoadAudio("resources/audio/menumove.wav");
	menuSelect = audio->LoadAudio("resources/audio/menuselect.wav");
}

void SoundPlayer::Exit()
{
	//unregister
	Listener::UnregisterFromEvent("PLAYERHURT");
	Listener::UnregisterFromEvent("GRAPPLEFIRE");
	Listener::UnregisterFromEvent("GRAPPLECONNECT");
	Listener::UnregisterFromEvent("ENEMYCOLLIDE");
	Listener::UnregisterFromEvent("PLANETCOLLIDE");
	Listener::UnregisterFromEvent("LIGHTORBCOLLIDE");
	Listener::UnregisterFromEvent("ENEMYFIRE");
	Listener::UnregisterFromEvent("ACHEIVEMENT");
	Listener::UnregisterFromEvent("GRAPPLEDETACH");
	Listener::UnregisterFromEvent("MENUMOVE");
	Listener::UnregisterFromEvent("MENUSELECT");
	//unload audio
	audio->UnloadAudio(playerHurt);
	audio->UnloadAudio(grappleFire);
	audio->UnloadAudio(grappleConnect);
	audio->UnloadAudio(enemyCollide);
	audio->UnloadAudio(planetCollide);
	audio->UnloadAudio(lightOrbCollide);
	audio->UnloadAudio(enemyFire);
	audio->UnloadAudio(acheivement);
	audio->UnloadAudio(grappleDetach);
	audio->UnloadAudio(menuMove);
	audio->UnloadAudio(menuSelect);
}